package com.behome.netty.netty_D.bean;

import com.behome.netty.netty_D.enums.TerminalDAnnotation;
import com.behome.netty.netty_D.enums.TerminalDType;

import java.nio.ByteBuffer;

/**
 * Created by cky on 2020/8/12.
 */

@TerminalDAnnotation(
        type = TerminalDType.QUERY_STATUS
)
public class TerminalDParamQuery extends BusinessCmdBase {
    private byte paramNum;
    private byte[] paramMarks;

    public TerminalDParamQuery() {
    }

    public byte getParamNum() {
        return this.paramNum;
    }

    public void setParamNum(byte paramNum) {
        this.paramNum = paramNum;
    }

    public byte[] getParamMarks() {
        return this.paramMarks;
    }

    public void setParamMarks(byte[] paramMarks) {
        this.paramMarks = paramMarks;
    }

    public boolean validateBeforeSerialize() {
        return this.paramNum != 0 && this.paramMarks != null && this.paramMarks.length == this.paramNum;
    }

    public byte[] serialize() {
        if(this.validateBeforeSerialize()) {
            int length = 1 + this.paramNum;
            ByteBuffer byteBuffer = ByteBuffer.allocate(length);
            byteBuffer.put(this.paramNum)
                    .put(this.paramMarks);
            return byteBuffer.array();
        } else {
            return null;
        }
    }

    public BusinessCmdBase deserialize(byte[] businessData) {
        return null;
    }
}
